
package com.shop.cloud.upms.admin.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.log.annotation.SysLog;
import com.shop.cloud.common.security.annotation.Inside;
import com.shop.cloud.upms.common.entity.TableArea;
import com.shop.cloud.upms.admin.service.TableAreaService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 地区表
 *
 * @author
 * @date 2023-10-10 15:51:20
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/tablearea")
@Tag(description = "tablearea", name = "地区表管理")
public class TableAreaController {

    private final TableAreaService tableAreaService;

    /**
     * 地区表分页列表
     * @param page 分页对象
     * @param tableArea 地区表
     * @return
     */
    @Operation(summary = "地区表分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ato.hasAuthority('upms:tablearea:index')")
    public R getPage(Page page, TableArea tableArea) {
        return R.ok(tableAreaService.page(page, Wrappers.query(tableArea)));
    }

    /**
     * 地区表查询
     * @param id
     * @return R
     */
    @Operation(summary = "地区表查询")
    @GetMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('upms:tablearea:get')")
    public R getById(@PathVariable("id") Integer id) {
        return R.ok(tableAreaService.getById(id));
    }

    /**
     * 地区表新增
     * @param tableArea 地区表
     * @return R
     */
    @Operation(summary = "地区表新增")
    @SysLog("新增地区表")
    @PostMapping
    @PreAuthorize("@ato.hasAuthority('upms:tablearea:add')")
    public R save(@RequestBody TableArea tableArea) {
        return R.ok(tableAreaService.save(tableArea));
    }

    /**
     * 地区表修改
     * @param tableArea 地区表
     * @return R
     */
    @Operation(summary = "地区表修改")
    @SysLog("修改地区表")
    @PutMapping
    @PreAuthorize("@ato.hasAuthority('upms:tablearea:edit')")
    public R updateById(@RequestBody TableArea tableArea) {
        return R.ok(tableAreaService.updateById(tableArea));
    }

    /**
     * 地区表删除
     * @param id
     * @return R
     */
    @Operation(summary = "地区表删除")
    @SysLog("删除地区表")
    @DeleteMapping("/{id}")
    @PreAuthorize("@ato.hasAuthority('upms:tablearea:del')")
    public R removeById(@PathVariable Integer id) {
        return R.ok(tableAreaService.removeById(id));
    }

    /**
     * 地区表分页List
     * @param tableArea 地区表
     * @return
     */
    @Operation(summary = "地区表分页List")
    @GetMapping("/list")
    public R getList(TableArea tableArea) {
        return R.ok(tableAreaService.list(Wrappers.query(tableArea)));
    }

    /**
     * 地区表分页List（服务间调用）
     * @param tableArea 地区表
     * @return
     */
    @Operation(summary = "地区表分页List（服务间调用）")
    @PostMapping("/inside/list")
    @Inside
    public R getInsideList(@RequestBody TableArea tableArea) {
        return R.ok(tableAreaService.list(Wrappers.query(tableArea)));
    }
}
